package com.autologistics.service;

import java.util.List;

import com.autologistics.dao.AdminDao;
import com.autologistics.model.Admin;
import com.autologistics.model.Disparter;
import com.autologistics.util.PageBean;

public class AdminServiceImpl implements AdminService{
	private AdminDao adminDao;
	
	public AdminDao getAdminDao() {
		return adminDao;
	}

	public void setAdminDao(AdminDao adminDao) {
		this.adminDao = adminDao;
	}

	/**
	 * @param ac
	 * @param pwd
	 * @return ����Ա 
	 * @author cl
	 */
	public Admin getByAccountPwd(String ac ,String pwd){
		return adminDao.getByAccountPwd(ac, pwd);	
	}
	public List<Admin> getByRole(int role){
		return adminDao.getByRole(role);
	}
	public Admin getById(int id){
		return adminDao.getById(id);
	}
	public Admin getByAccoint(String ac){
		return adminDao.getByAccoint(ac);
	}
	public List<Admin> getExceptAll(){
		return adminDao.getExceptAll();
	}

	public void save(Admin admin){
		adminDao.save(admin);
	}
	public void update(Admin admin){
		adminDao.update(admin);
	}
	public PageBean queryForOnePage(final int pageSize, int page,int allRow){
		System.out.println("allRow    "+allRow);
		int totalPage = PageBean.countTotalPage(pageSize, allRow); //总页数  
		System.out.println("totalPage    "+totalPage);
		
		final int offset = PageBean.countOffset(pageSize, page); //当前页开始记录  
		System.out.println("offset    "+offset);
		final int length = pageSize; // 每页记录数    
		final int currentPage = PageBean.countCurrentPage(page); // 当前页    
		List<Admin> list=adminDao.queryForOnePage(offset, length);
		//把分页信息保存到Bean当中    
		PageBean pageBean  = new PageBean();    
		pageBean.setPageSize(pageSize);    
		pageBean.setCurrentPage(currentPage);    
		pageBean.setAllRow(allRow);    
		pageBean.setTotalPage(totalPage);    
		pageBean.setAdminList(list);    
		return pageBean; 
		
		
	}
}
